<?php  include VIEWPATH.'common/head.php';  ?>
    <script type="text/javascript">
        var status = '<?php echo $_GET['status'];?>';
        if(status == '-1'){
            alert('fail:<?php echo $_GET['msg'];?>');
        }
        //隐藏
        function setDel(topic_id,status){
            var url = "index.php?c=topic&m=set_status";
            var param = {"id":topic_id, "status":status};
            common_ajax(url, param, function(data){
                if(data.errorCode == 0) {
                    //表单提交
                    window.location.href=  window.location.href;
                    return true;
                }else{
                    alert(data.errorMsg);
                }
            });
        }
    </script>
    <style>
        .checkbox_id{float: left;margin-top: 15px;
            margin-right: 5px;}
    </style>
    <body class="gray-bg">
    <div class="wrapper wrapper-content ">

        <div class="add-btn" style="float:right;">
            <div class="modal fade" id="topic_edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document" style="width: 70%;"><div class="modal-content"></div></div>
            </div>
        </div>
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <a href="index.php?c=topic&m=topic_edit&type=2" class="btn btn-danger" data-toggle="modal" data-target="#topic_edit">添加</a>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div style="margin-top: 15px;">
                            <form class="form-horizontal" id="f_form" action="index.php?c=<?php echo $_REQUEST['c'];?>&m=<?php echo $_REQUEST['m'];?>" name="form" method="post">
                                <div class="form-group">


                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">分类：</div>
                                    <div class="col-sm-2">
                                        <!--                                        全部/茉莉导入/麻花导入/用户上传/运营上传/签约用户上传-->
                                        <select name="category_id" class="form-control">
                                            <option <?php echo $category_id==''?"selected":""?> value="">全部</option>
                                            <?php
                                                foreach ($category_list as $k=>$v){
                                            ?>
                                            <option <?php echo $category_id==$k?"selected":""?> value="<?php echo $k;?>"><?php echo $v;?></option>
                                            <?php
                                                }
                                            ?>
                                        </select>
                                    </div>

                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">话题名：</div>
                                    <div class="col-sm-2">
                                        <input type="text" name="s_title" placeholder="请输入话题" class="input-sm form-control"  value="<?php echo $s_title;?>" autocomplete="off"/>
                                    </div>
                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">是否热门：</div>
                                    <div class="col-sm-2">
                                        <select name="is_hot" class="form-control">
                                            <option value="all" <?php echo $_REQUEST["is_hot"] == "all" ? "selected":"";?>>全部</option>
                                            <option value="1" <?php echo $_REQUEST["is_hot"] == 1 ? "selected":"";?>>是</option>
                                            <option value="0" <?php echo isset($_REQUEST["is_hot"]) && $_REQUEST["is_hot"] == 0 ? "selected":"";?>>否</option>
                                        </select>
                                    </div>

                                    <div class="col-sm-12" style="text-align: right;line-height: 30px;padding: 0px;height: 15px;"></div>

                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">帖子数量范围：</div>
                                    <div class="col-sm-2">
                                        <input type="text" name="s_num" placeholder="请输入数值：0-222" class="input-sm form-control"  value="<?php echo $s_num;?>" autocomplete="off"/>
                                    </div>

                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">是否隐藏：</div>
                                    <div class="col-sm-2">
                                        <select name="is_hide" class="form-control">
                                            <option <?php echo $is_hide==''?"selected":""?> value="">全部</option>
                                            <option <?php echo $is_hide==-1?"selected":""?> value="-1">是</option>
                                            <option <?php echo $is_hide==1?"selected":""?> value="1">否</option>
                                        </select>
                                    </div>

                                    <div class="col-sm-1" style="text-align: right;line-height: 30px;padding: 0px;">排序：</div>
                                    <div class="col-sm-2">
                                        <select name="order" class="form-control">
                                            <option value="1" <?php echo $_REQUEST["order"] == 1 ? "selected":"";?>>默认</option>
                                            <option value="2" <?php echo $_REQUEST["order"] == 2 ? "selected":"";?>>指定位置</option>
                                        </select>
                                    </div>

                                    <div class="col-sm-1">
                                        <button class="btn btn-sm btn-primary" type="submit"> 搜索 </button>
                                    </div>

                                </div>
                            </form>
                        </div>

                        <form class="form-horizontal" name="search" id="f_form" action="index.php?c=<?php echo $_REQUEST["c"];?>&m=<?php echo $_REQUEST["m"];?>" method="post">
                            <div class="tag-media-top" style="background: aliceblue;">
                                <div style="width: 5%;float: left">&nbsp;</div>
                                <div style="width: 11%;float: left">所属分类</div>
                                <div style="width: 8%;float: left">封面图</div>
                                <div style="width: 37%;float: left">
                                    话题
                                </div>
                                <div style="float: left;width: 12%;">
                                    关注数
                                </div>
                                <div style="float: left;width: 12%;">
                                    帖子数
                                </div>
                                <div style="float: left;width: 15%;">
                                    操作
                                </div>
                                <div class="clearfix"></div>
                            </div>
                            <?php foreach($topicList as $k => $c){ ?>
                                <div class="tag-media-top <?php if($c['status'] == -1){echo "display_none";}?>">

                                    <div class="checkbox_id" style="width: 5%;float: left; margin: 0px;">
                                        <input type="checkbox" name="topic_id[]" value="<?php echo $c['id'];?>" class="checkbox ck topic_id_up" />
                                    </div>
                                    <div style="width: 11%;float: left;">
                                        <?php echo $category_list[$c['parent_id']];?>

                                    </div>
                                    <div style="width: 8%;float: left;">
                                        <?php $imgPath = empty($c['img']) ? 'data/static/tag_default.jpg' : $c['img'];?>
                                        <img class="media-object" alt="64x64" src="<?php echo $imgPath;?>" style="width:48px;height:48px;">
                                    </div>
                                    <div class="tag-media-body" style="width: 37%; margin:0px;">
                                        <h4 class="media-heading">
                                            <a class="J_menuItem" data-names="帖子列表"  href="index.php?c=post&m=post_list&&s_topic_id=<?php echo $c['id']?>">
                                                <?php echo $c['title'];?>
                                            </a>
                                        </h4>
                                        <span><?php echo str_cut($c['description'],0,40) ? str_cut($c['description'],0,40) : '';?></span>
                                    </div>
                                    <div style="width: 12%;float: left;">
                                        <span class="i_z z" style="margin: 0px;"><strong><?php echo $c['follow_user_num'];?></strong><em class="xg1">关注数</em></span>
                                    </div>
                                    <div style="width: 12%;float: left;">
                                        <span class="i_z z" style="margin: 0px;"><strong><?php echo $c['post_num'];?></strong><em class="xg1">帖子数</em></span>
                                    </div>

                                    <div style="width: 15%;float: left;">
                                        <a href="index.php?c=topic&m=topic_edit&type=2&topic_id=<?php echo $c['id'];?>&page=<?php echo $page;?>" class="btn btn-warning warning_22" data-toggle="modal" data-target="#topic_edit">编辑</a>
                                        <button type="button" class="btn btn-warning warning_22" onclick="setDel(<?php echo $c['id'];?>,<?php echo $c['status'] == -1?1:-1;?>)"><?php echo $c['status'] == -1?"显示":'隐藏';?></button>

                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                            <?php } ?>

                            <div class="set_page">
                                <?php echo $multipage; ?>
                                <div class="set_del">
                                    <label class="l_c_sel" style="margin-left:0px;">
                                        <input type="checkbox" name="chkall" onclick="checkAll('prefix', this.form, 'topic_id')" class="c_sel" style="width:auto;">全选</label>
                                    <a href="javascript:void(0)" onclick="update_topic(1)">显示</a>
                                    <a href="javascript:void(0)" onclick="update_topic(-1)">隐藏</a>
                                    <a href="javascript:void(0)" onclick="set_hot(1)">添加热门</a>
                                    <a href="javascript:void(0)" onclick="set_hot(0)">取消热门</a>
                                </div>
                                <div class="clearfix"></div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <input type="hidden" id="topic_ids" value="">
    <script>
        function get_sel_ids(){
            var ids = document.getElementsByName('topic_id[]');
            var sel_ids = '';
            for (var i = 0; i < ids.length; i++){
                if (ids[i].checked) {
                    sel_ids += ids[i].value + ',';
                }
            }
            if(sel_ids === ''){
                return false;
            }
            sel_ids = sel_ids.substr(0,sel_ids.length - 1);
            if(sel_ids === ''){
                return false;
            }
            return sel_ids;
        }
        function update_topic(type) {
            var sel_ids = get_sel_ids();
            if(!sel_ids){
                alert('请选择要操作的话题');
                return false;
            }
            $("#topic_ids").val(sel_ids);
            setDel(sel_ids,type);
        }
        function set_hot(status){
            var sel_ids = get_sel_ids();
            if(!sel_ids){
                alert('请选择要操作的话题');
                return false;
            }
            var url = "index.php?c=topic&m=set_hot";
            var param = {"topic_id":sel_ids, "status":status};
            common_ajax(url, param, function(data){
                if(data.errorCode == 0) {
                    //表单提交
                    alert("更新成功");
                    return true;
                }else{
                    alert(data.errorMsg);
                }
            });
        }
    </script>

    <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js"></script>
<?php  include VIEWPATH.'common/footer.php';  ?>